const request = (options, isShowLoading = true) => {
    options.method && (options.method = options.method.toUpperCase());
    return new Promise((resolve, reject) => {
        if (isShowLoading) {
            uni.showLoading({
                title: "加载中",
            });
        }
        let HOST = '' ;
        // HOST = "http://localhost:7007";
        HOST = "https://findcreativeness.cn";
        const url = `${HOST}${options.url}`;
        uni.request({
            url,
            method: options.method || "GET",
            data: options.data || {},
            header: options.header || {
                "content-type": "application/x-www-form-urlencoded",
            },
            success: (res) => {
                if (res.statusCode !== 200) {
                    uni.showToast({
                        title: "网络出错，请稍后再试",
                        icon: "none",
                    });
                    return;
                }
                resolve(res.data);
            },
            fail: (err) => {
                reject(err);
            },
            complete: () => {
                if (isShowLoading) {
                    uni.hideLoading();
                }
            },
        });
    });
};

export default request;
